;(function() {
	'use strict';
	angular.module('controllers.resourcesWatchData.resourceMonitoring')
		.controller('rmAlarmNumExcavationController', alarmNumExcavation);

	function alarmNumExcavation($scope, rm, CoreService) {
		$scope.timeTypes = rm.rmService.TIMETYPE;
		$scope.standardTypes = rm.rmService.STANDARDTYPE;
		$scope.sendData = rm.rmService.SENDDATA;
		$scope.types = rm.rmService.TYPE;
		//控制查询条件拉上拉下   1为拉下  0 为拉上
		$scope.shoumun = {
			num: 1
		};
		//控制等待样式   false 为隐藏   true 为显示
		$scope._loading.show = false;
		var myEcharts = echarts.init(document.getElementById('doc'));
		var echartsConfig = echarts.config;
		myEcharts.on(echartsConfig.EVENT.CLICK,viewDown);
		$scope.show = {};
		$scope.search = function() {
			if ($scope.shoumun.num === 1) {
				$scope.shoumun.num = 1;
				return;
			}
			
			//时间粒度为天时，最多只能查询31天的数据
			var endTime = $scope.sendData.endTime.getTime();
			var startTime = $scope.sendData.startTime.getTime();
			var day = (endTime - startTime) / 1000 / 60 / 60 / 24;
			var hour = parseInt((endTime - startTime) / 1000 / 60 / 60);
			if ($scope.sendData.timeType === '1') {
				if (day > 30) {
					$scope.shoumun.num = 1;
					CoreService.dialog('粒度为天时,只能查询31天内的数据！');
					return;
				}
			} else {
				if (hour > 47) {
					$scope.shoumun.num = 1;
					CoreService.dialog('粒度为小时时,只能查询48小时内的数据！');
					return;
				}
			}
			$scope.send = rm.rmFn.fmtSendData($scope.sendData,$scope.equipmens);
			if($scope.send.equipmen.length === 0){
				$scope.send.equipmen = $scope.equipmens.map(function(eq){
					return eq.name;
				});
			}
			$scope.title = rm.rmFn.getTitle($scope.send);
			rm.rmFactory.queryAlarmNum($scope.send, function(res) {
				if (res.state === '10000') {
					$scope.items = res.data;
					$scope.totalCount = 14;
					rm.rmFn.getData(res.data,$scope.title,myEcharts);
					$scope.show.state = 'view';
					$scope.shoumun.num = 0;
				} else {
					CoreService.dialog('查询无数据');
				}
			});
		};
		function viewDown(){
			$scope.send.page = {
				currentPage: 1,
				pageSize: 5
			};
			$scope.show.state = 'table';
			$scope.$apply();
		}
		$scope.changeTime = rm.rmFn.changeTime;
		$scope.$watch('sendData.equipmenType',function(code){
			$scope.sendData.equipmen = [];
			code === '1' ? $scope.equipmens = rm.rmService.SOFTEQUIPMENTS : $scope.equipmens = rm.rmService.HARDEQUIPMENTS;
		});
		$scope.back = function(){
			$scope.show.state = 'view';
		};
	}
	alarmNumExcavation.$inject = ['$scope', 'rm', 'CoreService'];
})();